package org.minproject.my_library_back.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.minproject.my_library_back.common.CommonResponse;
import org.minproject.my_library_back.domain.Comment;
import org.minproject.my_library_back.domain.Library;
import org.minproject.my_library_back.service.LibraryService;
import org.minproject.my_library_back.mapper.LibraryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author Lenovo
* @description 针对表【library】的数据库操作Service实现
* @createDate 2024-11-21 09:11:46
*/
@Service
public class LibraryServiceImpl extends ServiceImpl<LibraryMapper, Library>
    implements LibraryService{

    @Autowired
    private LibraryMapper libraryMapper;

    @Override
    public CommonResponse<List<Library>> getLibraryByUserid(int userid) throws Exception {
        QueryWrapper<Library> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userid);
        List<Library> libraries=libraryMapper.selectList(queryWrapper);
        return CommonResponse.createForSuccess("查询成功",libraries);
    }

    @Override
    public CommonResponse<Library> addLibrary(Library library) throws Exception {
        libraryMapper.insert(library);
        return CommonResponse.createForSuccess("添加成功",library);
    }

    @Override
    public CommonResponse<Library> deleteLibrary(String libraryName) throws Exception {
        Library library=libraryMapper.selectById(libraryName);
        libraryMapper.deleteById(libraryName);
        return CommonResponse.createForSuccess("删除成功",library);
    }
}




